﻿using System.Xml.Linq;

namespace AzukiMap.MapSource
{
    public abstract class VectorSource : MapSource
    {
        public VectorSourceTypes VectorType { get; internal set; }

        protected VectorSource(VectorSourceTypes type)
            : base(MapSourceTypes.Vector)
        {
            VectorType = type;
        }

        protected VectorSource(string name, VectorSourceTypes vectorType, int srid)
            : base(name, MapSourceTypes.Vector, srid)
        {
            VectorType = vectorType;
        }

        public override XElement ToXml()
        {
            return ToXml("VectorSource");
        }
            
        public override XElement ToXml(string elementName)
        {
            XElement vectorSourceXml = base.ToXml(elementName);
            vectorSourceXml.Add(
                new XElement("VectorType", VectorType.ToString())
                );

            return vectorSourceXml;
        }

        public override void Parse(XElement mapSourceXml)
        {
            base.Parse(mapSourceXml);
            VectorType = (VectorSourceTypes)_xmlCommon.GetEnumElement(mapSourceXml, "VectorType", typeof(VectorSourceTypes));
        }
    }
}
